<?php
/**
 * Created by PhpStorm.
 * User: ZHOUZHOU'
 * Date: 17-10-23
 * Time: 下午10:46
 */

namespace Admin\Controller;

class WebConfigController extends CommonController{

    public function config_list(){
        $rel = M('sys_configure')->select();
        $this->assign('list',$rel);
        $this->display();
    }

    public function config_add(){
        if(IS_POST) {
            $data = I('post.');

            $data['configure_value'] = json_encode($data['configure_value']);
            $rel = M('sys_configure')->add($data);

            //售卖地区配置添加
            $ids='';
            if(!empty($data['title'])) {
                foreach ($data['title'] as $k => $v) {
                    $map['region_name'] = array('like', '%' . $v . '%');
                    $id = M('region_list')->where($map)->find();
                    $ids = $ids . ',' . $id['region_id'];
                }
                $ids = substr($ids,1);

                $ids = explode(',', $ids);
                $data['configure_value'] = json_encode($ids);
                //$data['configure_value'] = json_encode($data['configure_value']);
                $rel = M('sys_configure')->add($data);
            }


            if ($rel) {
                die(json_encode(array('state' => 200, 'rel' => '成功')));
            }
            }



        //地区
        $city = S('city');

        if(!$city) {
            $id = M('region_list')->field('region_id')->where(array('parent_region_id' => 1))->select();
            foreach ($id as $k => $v) {
                $list = M('region_list')->where(array('parent_region_id' => $v['region_id']))->select();

                foreach ($list as $ks => $vs) {
                    $city[]['name'] = $vs['region_name'];
                    $city_id[]['id'] = $vs['region_id'];
                }

            }

            for ($i = 0; $i < count($city); $i++) {
                $city[$i]['id'] = $city_id[$i]['id'];
            }
            $city = json_encode($city);
            S('city', $city,864000);
        }

        $this->assign('city',$city);


        $this->display();
    }
}